package com.blockmeta.bbs.immodule.corebean;

import com.blockmeta.bbs.baselibrary.base.app.BaseApp;
import com.blockmeta.bbs.immodule.corebean.Impl.ChatMessageDomainService;
import com.blockmeta.bbs.immodule.corebean.Impl.CircleDomainService;
import com.blockmeta.bbs.immodule.corebean.Impl.DomainCommonManger;
import com.blockmeta.bbs.immodule.corebean.Impl.ImMetaManager;
import com.blockmeta.bbs.immodule.corebean.Impl.TodoDomainService;
import com.blockmeta.bbs.immodule.corebean.Impl.UserDomainService;

public class IMDomainFactory {

    private static IMMetaBase imMetaBaseService;
    private static ICircleDomainService circleDomainService;
    private static IUserDomainService userDomainService;
    private static IChatMessageDomainService chatMessageDomainService;
    private static IDomainCommonManger domainCommonManger;
    private static ITodoDomainService todoDomainService;
    public static IMMetaBase createIMMetaService(){
        if(imMetaBaseService != null){
            return imMetaBaseService;
        }else {
            synchronized (IMMetaBase.class){
                if(imMetaBaseService == null){
                    imMetaBaseService = new ImMetaManager();
                }
            }
        }
        return imMetaBaseService;
    }


    public static ICircleDomainService createCircleDomainService(){
        if(circleDomainService == null){
            synchronized (ICircleDomainService.class){
                if(circleDomainService == null){
                    circleDomainService = new CircleDomainService(BaseApp.getApp());
                }
            }
        }
        return circleDomainService;

    }

    public static IUserDomainService createUserDomainService(){
        if(userDomainService == null){
            synchronized (IUserDomainService.class){
                if(userDomainService == null){
                    userDomainService = new UserDomainService(BaseApp.getApp());
                }
            }
        }
        return userDomainService;
    }

    public static IChatMessageDomainService createChatMessageDomainService() {
        if(chatMessageDomainService == null){
            synchronized (IChatMessageDomainService.class){
                if(chatMessageDomainService == null){
                    chatMessageDomainService = new ChatMessageDomainService(BaseApp.getApp());
                }
            }
        }
        return chatMessageDomainService;
    }

    public static IDomainCommonManger createDomainCommonManger() {
        if(domainCommonManger == null){
            synchronized (IDomainCommonManger.class){
                if(domainCommonManger == null){
                    domainCommonManger = new DomainCommonManger(BaseApp.getApp());
                }
            }
        }
        return domainCommonManger;
    }

    public static ITodoDomainService createTodoDomainService() {
        if(todoDomainService == null){
            synchronized (ITodoDomainService.class){
                if(todoDomainService == null){
                    todoDomainService = new TodoDomainService(BaseApp.getApp());
                }
            }
        }
        return todoDomainService;
    }
}
